#include <iostream>
#include <memory>
#include <pthread.h>
#include <vector>
#include <map>
#include "learn_7.hpp"

struct Address
{
    std::string city;
    std::string street;
    int number;

    REFLECT(city, street, number);
};

struct Student
{
    std::string name;
    int age;
    Address address;
    std::vector<std::string> hobbies;
    std::map<std::string, int> scores;

    REFLECT(name, age, address, hobbies, scores);
};



int main(void)
{
    std::string json_str = R"({
        "name": "Tom",
        "age": 20,
        "address": {
            "city": "Beijing",
            "number": 100
        },
        "hobbies": ["football", "basketball"],
        "scores": {
            "math": 90,
            "english": 80
        }
    })";

    auto ret = deserialize<Student>(fromString(json_str));

    if (std::holds_alternative<std::string_view>(ret)) {
        std::cerr << "Error: " << std::get<std::string_view>(ret) << "\n";
    } else {
        Student obj = std::get<Student>(ret);

        std::cout << "name: " << obj.name << ", age: " << obj.age 
                << ", address: " << obj.address.city << ", "
                << obj.address.street << ", " << obj.address.number << std::endl;
        std::cout << "hobbies: ";
        for (const auto& hobby : obj.hobbies) {
            std::cout << hobby << " ";
        }
        std::cout << std::endl;
        std::cout << "scores: ";
        for (const auto& [subject, score] : obj.scores) {
            std::cout << subject << ": " << score << " ";
        }
        std::cout << std::endl;
    }

    return 0;
}